package com.zxl.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxl.entity.GoodsType;
import com.zxl.service.IGoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @packageName com.zxl.controller
 * @ClassName
 * @Author zxl
 * @Description //TODO
 * @date
 **/
@RestController
@RequestMapping("/goodstype")
public class GoodsTypeController {

    @Autowired
    private IGoodsTypeService goodsTypeService;

    @RequestMapping("/list")
    public List<GoodsType> list(){
        return goodsTypeService.list();
    }

    @PostMapping("/updateGoodsType")
    public boolean updateGoodsType(@RequestBody GoodsType goodsType){
        return goodsTypeService.updateById(goodsType);
    }

    @RequestMapping("/deleteGoodsTypeById")
    public boolean deleteGoodsTypeById(@RequestParam("id") Integer id){
        return goodsTypeService.removeById(id);
    }
    @PostMapping("/addGoodsType")
    public boolean addGoodsType(@RequestBody GoodsType goodsType){
        return goodsTypeService.save(goodsType);
    }
    @RequestMapping("/findGoodsTypeByPid")
    public List<GoodsType> findGoodsTypeByPId(@RequestParam("pid") Integer pid){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("pid",pid);
        return goodsTypeService.list(wrapper);
    }
}
